﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace VigenereForms
{   /// <summary>
    /// 建立一个维吉尼亚密码加密类
    /// </summary>
    public class MyEncode
    {
        
         /// <summary>
            /// 定义明文
            /// </summary>
            public static string PlainText { get; set; }
            /// <summary>
            /// 定义密文
            /// </summary>
            public static string CipherText { get; set; }
            /// <summary>
            /// 定义密钥
            /// </summary>
            public static string Key { get; set; }
            /// <summary>
            /// 加密过程
            /// </summary>
            public static void EnCode()
            {
                for (int i = 0, j = 0; i < PlainText.Length; i++, j++)
                {
                    if (j == Key.Length) j = 0;
                    int Num = (Convert.ToInt32(PlainText[i]) + GetCodeNum(Key[j]) - 65) % 26; //求转化后字母的数字编号
                    CipherText += Convert.ToChar(Num + 'A');
                }
            }
            /// <summary>
            /// 求密钥字母的数字编号
            /// </summary>
            public static int GetCodeNum(char ch)
            {
                int CodeNum = ch - 'A';
                return CodeNum;
            }
        }
}
